# %% ####################################################
rm(list = ls())
library(LalRUtils)
libreq(
  data.table, zoo, tictoc, fixest, PanelMatch, patchwork,
  rio, magrittr, janitor, did, panelView, ggplot2, RPushbullet, ggiplot, 
  tidyverse, data.table, zoo, tictoc, fst, fixest, PanelMatch, patchwork,
  rio, magrittr, janitor, did, panelView, ggiplot, tictoc, binsreg, interflex
)

set.seed(42)
theme_set(lal_plot_theme())

notif = \(x) pbPost("note", x)

#------------------------------------------------------------------------------



#------------------------------------------------------------------------------
# Define Paths
#------------------------------------------------------------------------------

# R studio
setwd( dirname(rstudioapi::getActiveDocumentContext()$path) )
# R default : unccoment if you use default R
# setwd(getSrcDirectory(function(){})[1])
#------------------------------------------------------------------------------


#------------------------------------------------------------------------------
# Load Data
#------------------------------------------------------------------------------

vcf <- fread("vcf_data_complete.csv", sep = ",")
setnames( vcf, "d", "D")

#------------------------------------------------------------------------------


#------------------------------------------------------------------------------
# Table A1: Summary Statistics for primary analysis 
#           sample (VCF Data) - full sample
#------------------------------------------------------------------------------

# Import data
library(vtable)
vcf_data <- copy( vcf )
# %% summary table - VCF
sumvars = c('forest_index', 'green_index', 'built_index', 'sch', 'cover_1990')
summvars = c('notNA(x)', 'mean(x)', 'sd(x)', 'min(x)', 'pctile(x)[25]', 
             'median(x)', 'pctile(x)[75]', 'max(x)')
labs = c(
  'Forest cover index (0-100)',
  'Non-forest green index (0-100)',
  'Non-green index (0-100)',
  'Scheduled Status',
  'Forest Cover in 1990 (Ex-Ante)'
)
# %%
sumtable(vcf_data[, ..sumvars],
         digits=5,
         factor.percent = FALSE, factor.counts = FALSE, summ = summvars,
         labels = labs, title = "Summary Statistics for primary 
         analysis sample (VCF Data) - full sample",
         file = "appendix_tableA1.tex", 
         out = 'latex')

#------------------------------------------------------------------------------

